// read configuration

if (typeof ALVEOLE.css=="undefined")
	ALVEOLE.css = ALVEOLE.baseaddress + "alveole.css";




document.write('<LINK href="' + ALVEOLE.css +'" rel="stylesheet" type="text/css">');

if (typeof ALVEOLE.GUI=="undefined")
	ALVEOLE.GUI ={};


ALVEOLE.GUI.domid=function(id,func)
{
	return 'ALV' + id + func;
};
ALVEOLE.GUI.domclass=function(func)
{
	return 'ALV' + func;
};
ALVEOLE.GUI.window=function(windowId,windowTitle,parent)
{
	this.hide=function()
	{
		if (this.showAllways==false)
			this.window.style.display="none";
	};
	this.show=function()
	{
		this.window.style.display="block";
	};
	this.changeTitle=function(content)
	{
		this.title.innerHTML = content;
	};
	this.changeContent=function(content)
	{
		this.content.innerHTML = content;
	};
	this.appendChild=function(child)
	{
		this.content.appendChild(child);
	};
	this.setError=function(error)
	{
		this.error.innerHTML=error;
	};
	this.addLink=function(caption,func)
	{
		var link = document.createElement("a");
		link.href="#";
		link.onclick=func;
		link.innerHTML=caption;
		this.appendChild(link);
	};
	this.createDiv=function(divFunction,parent)
	{
		var div=ALVEOLE.GUI.createDiv(ALVEOLE.GUI.domid(this.windowId,divFunction),parent);
		div.className = ALVEOLE.GUI.domclass(divFunction);
		return div;
	};
	this.showAllways=false;
	
	this.windowId=windowId;
	this.window = this.createDiv("window",parent);
	
	this.title = this.createDiv("title",this.window);
	
	this.content = this.createDiv("content",this.window);
	this.content.style.paddingRight="1px";
	this.content.style.paddingLeft="1px";

	this.error = this.createDiv("error",this.content);
	this.changeTitle(windowTitle);

};
ALVEOLE.GUI.createDiv=function(id,parent)
{
	var div = document.createElement("div");
	div.id=id;
	parent.appendChild(div);
	return div;
};
ALVEOLE.GUI.windows = [];


ALVEOLE.GUI.setDomPosition=function(dom,type,symbol,left,top,width,height)
{
	dom.style.position=type;
	dom.style.left=left +"px";
	dom.style.width=width + symbol;
	dom.style.top=top +"px";
	dom.style.height=height + symbol;
};

ALVEOLE.GUI.setWindowPosition=function(windowId,type,left,top,width,height)
{
	ALVEOLE.GUI.setDomPosition(ALVEOLE.GUI.windows[windowId].window,type,"px",left,top,width,height);	
	ALVEOLE.GUI.windows[windowId].content.style.height=(height-13) + "px";
//	ALVEOLE.GUI.windows[windowId].content.style.backgroundColor="#f00";
};
ALVEOLE.GUI.createWindow=function(windowId,windowTitle,parent)
{
	ALVEOLE.GUI.windows[windowId] = new ALVEOLE.GUI.window(windowId,windowTitle,parent);
	return ALVEOLE.GUI.windows[windowId];
};
ALVEOLE.GUI.windowsExists=function(windowId)
{
	return typeof ALVEOLE.GUI.windows[windowId]!="undefined";
};
ALVEOLE.GUI.showWindowAlone=function(windowId)
{
	ALVEOLE.GUI.hideAllWindows();
	return ALVEOLE.GUI.showWindow(windowId);
};
ALVEOLE.GUI.showWindow=function(windowId)
{
	if (ALVEOLE.GUI.windowsExists(windowId))
	{
		ALVEOLE.GUI.windows[windowId].show();
		return true;
	}
	return false;
};

ALVEOLE.GUI.hideAllWindows=function()
{
	for (var i in ALVEOLE.GUI.windows)
		ALVEOLE.GUI.windows[i].hide();
};
ALVEOLE.GUI.getScreen=function()
{
	var winW = 630, winH = 460;
	if (document.body && document.body.offsetWidth) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
			document.documentElement &&
    document.documentElement.offsetWidth ) {
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
	return { winH:winH, winW:winW};
};

ALVEOLE.GUI.getParam =function( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
};
ALVEOLE.GUI.createForm=function(submitText,submitFunction)
{	
	this.items = new Array();
	this.submitText=submitText;
	this.submitFunction=submitFunction;
	this.currentItem = 0;
	this.form=document.createElement("form");
	this.addInput=function(caption,type,id)
	{
		domcaption = document.createElement("span");
		domcaption.innerHTML = caption;
		dominput = document.createElement("input");
		dominput.style.width=(ALVEOLE.GUI.width-7) + "px";
		dominput.type=type;
		dominput.id=id;
		this.form.appendChild(domcaption);
		this.form.appendChild(document.createElement("br"));
		this.form.appendChild(dominput);
		this.form.appendChild(document.createElement("br"));
		return this;
	};
	this.addText=function(caption,id)
	{ 
		return this.addInput(caption,"text",id);
	};
	this.addPassword=function(caption,id)
	{ 
		return this.addInput(caption,"password",id);
	};
	this.getDom=function()
	{
		dombutton = document.createElement("a");
		dombutton.href='#';
		dombutton.style.cssFloat="right";
		dombutton.innerHTML=this.submitText;
		dombutton.onclick=this.submitFunction;
		dombutton.form=this.form;
		breaker=document.createElement("div");
		breaker.style.clear="both";
		this.form.appendChild(dombutton);
		this.form.appendChild(breaker);

		return this.form;
	};
	return this;
};
ALVEOLE.GUI.serialize=function(form)
{
	res="";
	for (var i=0;i<form.elements.length;i++)
	{
		res+=form.elements[i].id;
		res+="=";
		res+=encodeURIComponent(form.elements[i].value);
		if (i!=form.elements.length-1) res+="&";
	}
	return res;
};
ALVEOLE.GUI.createFrame=function(windowId,windowTitle,parent)
{
	ALVEOLE.GUI.windows[windowId] = new ALVEOLE.GUI.window(windowId,windowTitle,parent);
	return ALVEOLE.GUI.windows[windowId];
};
screen=ALVEOLE.GUI.getScreen();
ALVEOLE.GUI.width=200;
ALVEOLE.GUI.body=ALVEOLE.GUI.createDiv("body",document.body);
ALVEOLE.GUI.body.style.width=ALVEOLE.GUI.width + "px";
ALVEOLE.GUI.body.style.height=screen.winH + "px";

